package org.xi.behavioral.observer;

import org.xi.behavioral.observer.api.Observer;
import org.xi.behavioral.observer.impl.MessagePublisher;
import org.xi.behavioral.observer.impl.Subscriber;

/**
 * 观察者模式
 */
public class Main {

    public static void main(String[] args) {
        MessagePublisher publisher = new MessagePublisher();

        Observer alice = new Subscriber("Alice");
        Observer bob = new Subscriber("Bob");

        publisher.registerObserver(alice);
        publisher.registerObserver(alice);
        publisher.registerObserver(bob);

        publisher.publishNewArticle("Breaking News: New Technology Unveiled!");
        System.out.println();

        // 假设Bob不再感兴趣，可以取消订阅
        publisher.removeObserver(bob);

        publisher.publishNewArticle("Exclusive Interview with a Famous Author");
    }
}
